//主窗口

import 'package:flutter/material.dart';
import 'package:flutter_breadcrumb/flutter_breadcrumb.dart';
import 'package:super_study_english_tool/panel/panel_main_index.dart';
import 'package:super_study_english_tool/panel/panel_main_local.dart';
import 'package:super_study_english_tool/panel/panel_main_net.dart';
import 'package:super_study_english_tool/panel/panel_my.dart';
import 'package:super_study_english_tool/widget/widget_screen_main_left_menu.dart';

class ScreenMain extends StatefulWidget {
  const ScreenMain({super.key});

  @override
  State<ScreenMain> createState() => _ScreenMainState();
}

class _ScreenMainState extends State<ScreenMain> {
  PanelMainIndex panelMainIndex = PanelMainIndex();
  PanelMainLocal panelMainLocal = PanelMainLocal();
  PanelMainNet panelMainNet = PanelMainNet();
  PanelMy panelMy = PanelMy();
  List<Widget> stackList = [];

  @override
  void initState() {
    super.initState();

    stackList = [panelMainIndex, panelMainLocal, panelMainNet, panelMy];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("测试"),
      ),
      body: Row(
        mainAxisAlignment: MainAxisAlignment.end,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(width: 100, child: WidgetScreenMainLeftMenu(onChanged: menuChange)),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [buildBreadcrumb(), buildMain()],
            ),
          ),
        ],
      ),
    );
  }

  List<String> pathList = ["首页", "网络", "电影"];
  // 面包屑导航
  buildBreadcrumb() {
    List<BreadCrumbItem> items = [];
    for (int i = 0; i < pathList.length; i++) {
      items.add(BreadCrumbItem(
          content: TextButton(
        child: Text(pathList[i]),
        onPressed: () {
          op(pathList[i]);
        },
      )));
    }
    return Container(
        height: 40,
        child: BreadCrumb(
          items: items,
          divider: Icon(Icons.chevron_right),
        ));
  }

  buildMain() {
    return Expanded(child: Stack(children: stackList));
  }

  void op(String opCMD) {
    print("op${opCMD}");
  }

  void menuChange(String menuName) {
    print("${menuName}");
    switch (menuName) {
      case "showIndex":
        pathList = ["首页"];
        stackList.remove(panelMainIndex);
        stackList.add(panelMainIndex);
        setState(() {});
        break;
      case "showNet":
        pathList = ["首页", "网络"];
        stackList.remove(panelMainNet);
        stackList.add(panelMainNet);
        setState(() {});
        break;
      case "showLocal":
        pathList = ["首页", "本地"];
        stackList.remove(panelMainLocal);
        stackList.add(panelMainLocal);
        setState(() {});
        break;
      case "showMy":
        pathList = ["首页", "我的"];
        stackList.remove(panelMy);
        stackList.add(panelMy);
        setState(() {});
        break;
    }
  }
}

class MainDrawer extends Drawer {}
